
package at.fhooe.mcm12.java.serializer;

import java.util.HashMap;

import at.fhooe.mcm12.java.enums.OutputFormat;
import at.fhooe.mcm12.java.sensors.data.GPSPosition;
import at.fhooe.mcm12.java.utils.TimeUtils;

public class GPSSerializer extends SensorSerializer<GPSPosition> {

	static final String PATH = "logs/gps/gps_log";
	private final String[] m_tags;


	public GPSSerializer() {
		m_tags = new String[] { "timestamp", "latitude", "longitude",
				"altitude" };
		m_writers = new HashMap<>();
		m_writers.put(OutputFormat.XML, new XMLWriter());
		m_writers.put(OutputFormat.Text, new TextWriter());
		m_writers.put(OutputFormat.CSV, new CSVWriter());
	}

	@Override
	public void serialize(OutputFormat _format, GPSPosition _value) {
		String[] values = new String[] {
				TimeUtils.getCurrentTimeStamp(_value.getTimestamp()),
				String.valueOf(_value.getLatitude()),
				String.valueOf(_value.getLongitude()),
				String.valueOf(_value.getAltitude()) };
		m_writers.get(_format).log(PATH, m_tags, values);
	}
}
